from interface.member import MemberInterface
from utils.send_method import SendMethod
from pprint import pprint


class AddressInterface:
    def __init__(self, headers):
        self.url = 'http://47.108.206.100:8085'
        self.headers = headers

    def add_address(self, payload):
        method = 'post'
        url = self.url + '/member/address/add'
        return SendMethod.send_method(method=method, url=url, json=payload, headers=self.headers)

    def get_address_list(self):
        method = 'get'
        url = self.url + '/member/address/list'
        return SendMethod.send_method(method=method, url=url, headers=self.headers)


if __name__ == '__main__':
    body = {
        "username": "liyimei",
        "password": "123456"
    }
    headers = MemberInterface().get_token(body)
    address = AddressInterface(headers)
    payload = {
        "city": "武汉市",
        "defaultStatus": 0,
        "detailAddress": "汤逊湖北路",
        "id": 0,
        "memberId": 5607,
        "name": "源码",
        "phoneNumber": "18829291929",
        "postCode": "123456",
        "province": "湖北省",
        "region": "杨桥湖"
    }
    pprint(address.add_address(payload=payload))
    pprint(address.get_address_list())
